<template>
  <el-radio-group v-model="direction">
  <el-radio label="ltr">从左往右开</el-radio>
  <el-radio label="rtl">从右往左开</el-radio>
  <el-radio label="ttb">从上往下开</el-radio>
  <el-radio label="btt">从下往上开</el-radio>
</el-radio-group>

<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
  点我打开
</el-button>

<el-drawer
  title="我是标题"
  v-model= "drawer"
  :direction="direction"
  :before-close="handleClose">
  <span>我来啦!</span>
</el-drawer>
</template>

<script>
import { reactive, toRefs, getCurrentInstance } from 'vue'

export default {
  setup () {
    const { ctx } = getCurrentInstance()
    const state = reactive({
      drawer: false,
      direction: 'rtl'
    })
    const handleClose = (done) => {
      ctx.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
    return {
      ...toRefs(state),
      handleClose
    }
  }
}
</script>

<style scoped>

</style>
